package com.flower8.service.impl;

import com.flower8.controller.SysConfigController;
import com.flower8.dao.GoodsDao;
import com.flower8.model.ActiveGoods;
import com.flower8.service.GoodsService;
import com.flower8.service.SysConfigService;
import com.flower8.utils.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @Description: 大转盘奖品
 * @Author: tanglin
 * @Date: 2020/3/9 18:13
 * @Version: 1.0
 */
@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsDao goodsDao;
    @Autowired
    private SysConfigService sysConfigService;


    /**
     * 查询大转盘奖品列表
     * @param pd
     * @return
     * @throws Exception
     */
    @Override
    public List<Map> getGoodsList(PageData pd) throws Exception {
        return goodsDao.getGoodsList(pd);
    }

    /**
     * 查询大转盘奖品列表
     *
     * @param pd
     * @return
     * @throws Exception
     */
    @Override
    public int getGoodsCount(PageData pd) throws Exception {
        return goodsDao.getGoodsCount(pd);
    }

    /**
     * 根据大转盘奖品ID查询
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Override
    public Map getGoodsById(long id) throws Exception {
        return goodsDao.getGoodsById(id);
    }

    /**
     * 更新大转盘奖品
     *
     * @param goods
     * @throws Exception
     */
    @Override
    @Transactional
    public void updateGoods(ActiveGoods goods) throws Exception {
        goodsDao.updateGoods(goods);
        //更新版本号
        goodsDao.updVersion();
        //重置大转盘分布
        sysConfigService.newBigWheel();
    }
}
